package com.byxy.action.payInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * Servlet implementation class BasicInfoDelServlet
 */
@WebServlet("/PayInfoDelServlet")
public class PayInfoDelServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try {

			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			String url = "jdbc:sqlserver://127.0.0.1:1433;databasename=PartyMember";
			String username = "sa";
			String password = "123456";
			Connection conn = DriverManager.getConnection(url, username, password);
			String sql = "DELETE FROM PayInfo WHERE id=?";
			PreparedStatement ps = conn.prepareStatement(sql);
			String ID[] = request.getParameterValues("delid");
			if (ID.length > 0) {
				for (int i = 0; i < ID.length; i++) {
					ps.setInt(1, Integer.parseInt(ID[i]));
					ps.addBatch();
				}
			}
			ps.executeBatch();
			ps.close();
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.sendRedirect("PayInfoFindAllServlet");
	}

}
